<!DOCTYPE html >
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0 ,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <title>结算页面</title>

    <link href="../AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css"/>
    <link href="../layui/css/layui.css" rel="stylesheet" type="text/css" />

    <link href="../basic/css/demo.css" rel="stylesheet" type="text/css"/>
    <link href="../css/cartstyle.css" rel="stylesheet" type="text/css"/>

    <link href="../css/jsstyle.css" rel="stylesheet" type="text/css"/>

    <script type="text/javascript" src="../js/address.js"></script>

</head>

<body>

<!--顶部导航条 -->
<div class="am-container header">
    <ul class="message-l">
        <div class="topMessage">
            <div class="menu-hd">
                <a href="/login" id="user" target="_top" class="h">亲，请登录</a>
                <a href="/register" id="register" target="_top">免费注册</a>
            </div>
        </div>
    </ul>
    <ul class="message-r">
        <div class="topMessage home">
            <div class="menu-hd"><a href="/" target="_top" class="h">商城首页</a></div>
        </div>
        <div class="topMessage my-shangcheng">
            <div class="menu-hd MyShangcheng"><a href="/information/" target="_top"><i
                    class="am-icon-user am-icon-fw"></i>个人中心</a>
            </div>
        </div>
        <div class="topMessage mini-cart">
            <div class="menu-hd"><a id="mc-menu-hd" href="#" target="_top"><i
                    class="am-icon-shopping-cart  am-icon-fw"></i><span>购物车</span><strong id="J_MiniCartNum"
                                                                                             class="h">0</strong></a>
            </div>
        </div>
        <div class="topMessage favorite">
            <div class="menu-hd"><a href="#" target="_top"><i
                    class="am-icon-heart am-icon-fw"></i><span>收藏夹</span></a>
            </div>
        </div>
    </ul>
</div>

<!--悬浮搜索框-->

<div class="nav white">
    <div class="logo"><img src="../images/logo.png"/></div>
    <div class="logoBig">
        <li><img src="../images/logobig.png"/></li>
    </div>

    <div class="search-bar pr">
        <a name="index_none_header_sysc" href="#"></a>
        <form>
            <input id="searchInput" name="index_none_header_sysc" type="text" placeholder="搜索" autocomplete="off">
            <input id="ai-topsearch" class="submit am-btn" value="搜索" index="1" type="submit">
        </form>
    </div>
</div>

<div class="clear"></div>
<div class="concent">
    <!--地址 -->
    <div class="paycont">
        <div class="address">
            <h3>确认收货地址 </h3>
            <div class="control">
                <div class="tc-btn createAddr theme-login am-btn am-btn-danger">使用新地址</div>
                <div class="tc-btn   am-btn am-btn-danger"><a href="/information/memberAddress" style="color: #ffffff" target="_blank">管理我的地址</a></div>
            </div>
            <div class="clear"></div>
            <ul id="addressUL">
                <div class="per-border"></div>
                <li class="user-addresslist">
                    <div class="address-left">
                        <div class="user DefaultAddr">

										<span class="buy-address-detail">   
                   <span class="buy-user">艾迪 </span>
										<span class="buy-phone">15877777777</span>
										</span>
                        </div>
                        <div class="default-address DefaultAddr">
                            <span class="buy-line-title buy-line-title-type">收货地址：</span>
                            <span class="buy--address-detail">
								   <span class="province">湖北</span>省
										<span class="city">武汉</span>市
										<span class="dist">武昌</span>区
										<span class="street">东湖路75号众环大厦9栋9层999</span>
										</span>

                            </span>
                        </div>
                        <ins class="deftip hidden">默认地址</ins>
                    </div>
                    <div class="address-right">
                        <span class="am-icon-angle-right am-icon-lg"></span>
                    </div>
                    <div class="clear"></div>
                </li>
            </ul>

            <div class="clear"></div>
        </div>
        <!--物流 -->
        <div class="logistics">
            <h3>选择物流方式</h3>
            <ul class="op_express_delivery_hot">
                <li data-value="yuantong" class="OP_LOG_BTN  "><i class="c-gap-right"
                                                                  style="background-position:0px -468px"></i>圆通<span></span>
                </li>
                <li data-value="shentong" class="OP_LOG_BTN  "><i class="c-gap-right"
                                                                  style="background-position:0px -1008px"></i>申通<span></span>
                </li>
                <li data-value="yunda" class="OP_LOG_BTN  "><i class="c-gap-right"
                                                               style="background-position:0px -576px"></i>韵达<span></span>
                </li>
                <li data-value="zhongtong" class="OP_LOG_BTN op_express_delivery_hot_last "><i class="c-gap-right"
                                                                                               style="background-position:0px -324px"></i>中通<span></span>
                </li>
                <li data-value="shunfeng" class="OP_LOG_BTN  op_express_delivery_hot_bottom"><i class="c-gap-right"
                                                                                                style="background-position:0px -180px"></i>顺丰<span></span>
                </li>
            </ul>
        </div>
        <div class="clear"></div>

        <!--支付方式-->
        <div class="logistics">
            <h3>选择支付方式</h3>
            <ul class="pay-list">
                <li class="pay card"><img src="../images/wangyin.jpg"/>银联<span></span></li>
                <li class="pay qq"><img src="../images/weizhifu.jpg"/>微信<span></span></li>
                <li class="pay taobao"><img src="../images/zhifubao.jpg"/>支付宝<span></span></li>
            </ul>
        </div>
        <div class="clear"></div>

        <!--订单 -->
        <div class="concent">
            <div id="payTable">
                <h3>确认订单信息</h3>
                <div class="cart-table-th">
                    <div class="wp">

                        <div class="th th-item">
                            <div class="td-inner">商品信息</div>
                        </div>
                        <div class="th th-price">
                            <div class="td-inner">单价</div>
                        </div>
                        <div class="th th-amount">
                            <div class="td-inner">数量</div>
                        </div>
                        <div class="th th-sum">
                            <div class="td-inner">金额</div>
                        </div>
                        <div class="th th-oplist">
                            <div class="td-inner">配送方式</div>
                        </div>

                    </div>
                </div>
                <div class="clear"></div>

                <tr class="item-list">
                    <div class="bundle  bundle-last">

                        <div class="bundle-main">
                            <ul class="item-content clearfix" th:each="cart:${carts}">
                                <div class="pay-phone">
                                    <li class="td td-item">
                                        <div class="item-pic">
                                            <a href="#" class="J_MakePoint">
                                                <img th:src="${cart.productImg}" style="width: 80px;height: 80px"
                                                     class="itempic J_ItemImg"></a>
                                        </div>
                                        <div class="item-info">
                                            <div class="item-basic-info">
                                                <a href="#" class="item-title J_MakePoint" data-point="tbcart.8.11"
                                                   th:text="${cart.productName}"></a>
                                            </div>
                                        </div>
                                    </li>
                                    <li class="td td-info">
                                        <!-- <div class="item-props">
                                             <span class="sku-line">颜色：12#川南玛瑙</span>
                                             <span class="sku-line">包装：裸装</span>
                                         </div>-->
                                    </li>
                                    <li class="td td-price">
                                        <div class="item-price price-promo-promo">
                                            <div class="price-content">
                                                <em class="J_Price price-now" th:text="${cart.price}"></em>
                                            </div>
                                        </div>
                                    </li>
                                </div>
                                <li class="td td-amount">
                                    <div class="amount-wrapper ">
                                        <div class="item-amount ">
                                            <span class="phone-title">购买数量</span>
                                            <div class="sl">
                                                <a href="#" class="item-title J_MakePoint" data-point="tbcart.8.11"
                                                   th:text="${cart.amount}"></a>
                                                <!--<input class="min am-btn" name="" type="button" value="-"/>-->
                                                <!--<input class="text_box" name="" disabled="disabled" type="text" th:text="${cart.amount}"
                                                       style="width:30px;"/>-->
                                                <!--<input class="add am-btn" name="" type="button" value="+"/>-->
                                            </div>
                                        </div>
                                    </div>
                                </li>
                                <li class="td td-sum">
                                    <div class="td-inner">
                                        <em tabindex="0" class="J_ItemSum number"
                                            th:text="${cart.amount*cart.price}"></em>
                                    </div>
                                </li>
                                <li class="td td-oplist">
                                    <div class="td-inner">
                                        <span class="phone-title">配送方式</span>
                                        <div class="pay-logis">
                                            包邮
                                        </div>
                                    </div>
                                </li>

                            </ul>
                            <div class="clear"></div>
                        </div>
                    </div>
                </tr>
                <div class="clear"></div>
            </div>

            <tr id="J_BundleList_s_1911116345_1" class="item-list">
                <div id="J_Bundle_s_1911116345_1_0" class="bundle  bundle-last">
                    <div class="bundle-main">

                        <div class="clear"></div>

                    </div>
                </div>
            </tr>
        </div>
        <div class="clear"></div>
        <div class="pay-total">
            <!--留言-->
            <div class="order-extra">
                <div class="order-user-info">
                    <div id="holyshit257" class="memo">
                        <label>买家留言：</label>
                        <input type="text" title="选填,对本次交易的说明（建议填写已经和卖家达成一致的说明）"
                               placeholder="选填,建议填写和卖家达成一致的说明"
                               class="memo-input J_MakePoint c2c-text-default memo-close">
                        <div class="msg hidden J-msg">
                            <p class="error">最多输入500个字符</p>
                        </div>
                    </div>
                </div>

            </div>
            <!--优惠券 -->
            <div class="buy-agio">
                <li class="td td-coupon">

                    <!--<span class="coupon-title">优惠券</span>
                    <select data-am-selected>
                        <option value="a">
                            <div class="c-price">
                                <strong>￥8</strong>
                            </div>
                            <div class="c-limit">
                                【消费满95元可用】
                            </div>
                        </option>
                        <option value="b" selected>
                            <div class="c-price">
                                <strong>￥3</strong>
                            </div>
                            <div class="c-limit">
                                【无使用门槛】
                            </div>
                        </option>-->
                    </select>
                </li>

                <li class="td td-bonus">

                    <!--<span class="bonus-title">红包</span>
                    <select data-am-selected>
                        <option value="a">
                            <div class="item-info">
                                ¥50.00<span>元</span>
                            </div>
                            <div class="item-remainderprice">
                                <span>还剩</span>10.40<span>元</span>
                            </div>
                        </option>
                        <option value="b" selected>
                            <div class="item-info">
                                ¥50.00<span>元</span>
                            </div>
                            <div class="item-remainderprice">
                                <span>还剩</span>50.00<span>元</span>
                            </div>
                        </option>
                    </select>-->

                </li>

            </div>
            <div class="clear"></div>
        </div>
        <!--含运费小计 -->
        <div class="buy-point-discharge " >
            <p class="price g_price ">
                合计（含运费） <span>¥</span><em class="pay-sum" th:text="${sum}"></em>
            </p>
        </div>

        <!--信息 -->
        <div class="order-go clearfix">
            <div class="pay-confirm clearfix">
                <div class="box">
                    <div tabindex="0" id="holyshit267" class="realPay"><em class="t">实付款：</em>
                        <span class="price g_price ">
                                    <span>¥</span> <em class="style-large-bold-red " id="J_ActualFee" th:text="${sum}">244.00</em>
											</span>
                    </div>

                    <div id="holyshit268" class="pay-address">

                        <p class="buy-footer-address">
                            <span class="buy-line-title buy-line-title-type">寄送至：</span>
                            <span class="buy--address-detail">
                                <span class="province" id="sheng">湖北</span>
								<span class="city">武汉</span>
                                <span class="dist">洪山</span>
                                <span class="street">雄楚大道666号(中南财经政法大学)</span>
                            </span>

                        </p>
                        <p class="buy-footer-address">
                            <span class="buy-line-title">收货人：</span>
                            <span class="buy-address-detail">
                                <span class="buy-user" id="shouhuoren">艾迪 </span>
                                <span class="buy-phone">15871145629</span>
                            </span>
                        </p>
                    </div>
                </div>

                <form method="post" action="/order/save">
                <div id="holyshit269" class="submitOrder">
                    <input type="hidden" name="ids" id="ids" th:value="${ids}">
                    <input type="hidden" name="addId" id="addId">
                    <div class="go-btn-wrap">
                        <button id="J_Go" class="btn-go"  style="margin-left: 860px">提交订单</button>
                    </div>
                </div>
                </form>
                <div class="clear"></div>
            </div>
        </div>
    </div>

    <div class="clear"></div>
</div>
</div>
<div class="footer">
    <div class="footer-hd">
        <p>
            <a href="#">恒望科技</a>
            <b>|</b>
            <a href="#">商城首页</a>
            <b>|</b>
            <a href="#">支付宝</a>
            <b>|</b>
            <a href="#">物流</a>
        </p>
    </div>
    <div class="footer-bd">
        <p>
            <a href="#">关于恒望</a>
            <a href="#">合作伙伴</a>
            <a href="#">联系我们</a>
            <a href="#">网站地图</a>
            <em>© 2015-2025 Hengwang.com 版权所有</em>
        </p>
    </div>
</div>
</div>
<div class="theme-popover-mask"></div>
<div class="theme-popover" style="width: 850px;height: 500px;">

    <!--标题 -->
    <div class="am-cf am-padding" >
        <div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">新增地址</strong> / <small>Add
            address</small></div>
    </div>
    <hr/>

    <div class="am-u-md-12">
        <!--<form class="am-form am-form-horizontal">

            <div class="am-form-group">
                <label for="user-name" class="am-form-label">收货人</label>
                <div class="am-form-content">
                    <input type="text" id="user-name" placeholder="收货人">
                </div>
            </div>

            <div class="am-form-group">
                <label for="user-phone" class="am-form-label">手机号码</label>
                <div class="am-form-content">
                    <input id="user-phone" placeholder="手机号必填" type="email">
                </div>
            </div>

            <div class="am-form-group">
                <label for="user-phone" class="am-form-label">所在地</label>
                <div class="am-form-content address">
                    <select data-am-selected>
                        <option value="a">浙江省</option>
                        <option value="b">湖北省</option>
                    </select>
                    <select data-am-selected>
                        <option value="a">温州市</option>
                        <option value="b">武汉市</option>
                    </select>
                    <select data-am-selected>
                        <option value="a">瑞安区</option>
                        <option value="b">洪山区</option>
                    </select>
                </div>
            </div>

            <div class="am-form-group">
                <label for="user-intro" class="am-form-label">详细地址</label>
                <div class="am-form-content">
                    <textarea class="" rows="3" id="user-intro" placeholder="输入详细地址"></textarea>
                    <small>100字以内写出你的详细地址...</small>
                </div>
            </div>

            <div class="am-form-group theme-poptit">
                <div class="am-u-sm-9 am-u-sm-push-3">
                    <div class="am-btn am-btn-danger">保存</div>
                    <div class="am-btn am-btn-danger close">取消</div>
                </div>
            </div>
        </form>-->
        <form class="am-u-md-12 layui-form"  lay-filter="addressForm" >
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px">收货人</label>
                <div class="layui-input-block">
                    <input type="text" name="contactName" lay-verify="title" autocomplete="off" placeholder="收货人" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user-phone" class="layui-form-label" style="width: 100px">手机号码</label>
                <div class="layui-input-block">
                    <input  class="layui-input" name="phone" id="user-phone" placeholder="手机号必填" type="email">
                </div>
            </div>

            <div class="layui-form-item" id="area-picker">
                <div class="layui-form-label" style="width: 100px;margin-left: 10px">网点地址</div>
                <div class="layui-input-inline" style="width: 200px;">
                    <select name="province"  class="province-selector" data-value="山东省">
                        <option value="">请选择省</option>
                    </select>
                </div>
                <div class="layui-input-inline" style="width: 200px;">
                    <select name="city" class="city-selector" data-value="菏泽市">
                        <option value="">请选择市</option>
                    </select>
                </div>
                <div class="layui-input-inline" style="width: 200px;">
                    <select name="district" class="county-selector" data-value="">
                        <option value="">请选择区</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="user-intro" class="layui-form-label" style="width: 100px">详细地址</label>
                <div class="layui-input-block">
                                        <textarea  class="layui-textarea" rows="address" name="address" id="user-intro"
                                                   placeholder="输入详细地址"></textarea>
                    <small>100字以内写出你的详细地址...</small>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button id="saveBtn" type="button" class="layui-btn">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    <!--<button type="button" id="closeForm" class="layui-btn layui-btn-primary">取消</button>-->

                    <div class="am-form-group theme-poptit" style="margin-top: -50px;margin-left: 0px;">
                        <div class="am-u-sm-9 am-u-sm-push-3">

                            <!--<div class="am-btn am-btn-danger">保存</div>-->

                            <div class="am-btn am-btn-danger close" style="height: 38px;width: 70px">取消</div>
                        </div>
                    </div>
                </div>
            </div>

        </form>
    </div>
</div>

<div class="clear"></div>

<script type="text/html" id="memberAddressTemplate">
    {{# layui.each(d,function(index,memberAddress){ }}
    <div class="per-border"></div>
        <li class="user-addresslist {{memberAddress.defaultAddr === 0 ? 'defaultAddr' : ''}}">
            <input type="hidden" name="defaultAddr" value="{{memberAddress.defaultAddr}}">
            <span type="hidden" class="addId" >{{memberAddress.id}}</span>
            <div class="address-left">
                <div class="user DefaultAddr">
                                            <span class="buy-address-detail">
                       <span class="buy-user">{{memberAddress.contactName}} </span>
                                            <span class="buy-phone">{{memberAddress.phone}}</span>
                                            </span>
                </div>
                <div class="default-address DefaultAddr">
                    <span class="buy-line-title buy-line-title-type">收货地址：</span>
                    <span class="buy--address-detail">
                                       <span class="province">{{memberAddress.province}}</span>
                                            <span class="city">{{memberAddress.city}}</span>
                                            <span class="dist">{{memberAddress.district}}</span>
                        <br>
                                            <span class="street">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{memberAddress.address}}</span>
                                        </span>
                    </span>
                </div>
                <ins class="deftip {{memberAddress.defaultAddr === 0 ? '' : 'hidden'}} ">默认地址</ins>
            </div>
            <div class="address-right">
                <span class="am-icon-angle-right am-icon-lg"></span>
            </div>
        <!--<div class="new-addr-btn">
            <a href="#" class="{{memberAddress.defaultAddr === 0 ? 'hidden' : ''}}">设为默认</a>
            <span class="new-addr-bar hidden">|</span>
        </div>-->
        <div class="clear"></div>
    </li>
    {{# });}}
</script>
<script type="text/javascript" src="/layui/layui.js"></script>
<script type="text/javascript">
    layui.use("layer",function () {
        var $ = layui.jquery;
        var laytpl=layui.laytpl;


        
        $.get("/selectByUsername",function (m) {
            if (m.data !=null){
                // 创建并设置带有圆角、自适应填充的用户头像
                var imgElement = $("<img>")
                    .attr("src", m.data.avatar)
                    .attr("style", "width:50px;height:50px;border-radius:50%;");
                // 把新的图片元素插入到"user"元素之前
                imgElement.insertBefore($("#user"));
                // 更新用户姓名
                $("#user").text("             "+m.data.username);
                $("#user").attr("href","/information/");
                // 删除原来的"register"元素
                $("#register").remove();
            }
        });

        $.get("/information/selectMemberAddress",function(memberAddress){
            laytpl($("#memberAddressTemplate").html()).render(memberAddress,function (ht) {
                $("#addressUL").html(ht);
            })
        })

        /*$("body").on("click","#J_Go",function() {
            $.post("/order/save",{ids:$("#ids").val(),addId:$("#addId").val()},function() {

            })
        })*/

        var addressList = document.getElementById('addressUL'); // 获取地址列表ul元素
        // 绑定点击事件
        addressList.addEventListener('click', function(evt) {
            if (evt.target.tagName === 'LI') { // 判断点击目标是否为li元素
                // 清除所有li元素的defaultAddr类名
                var items = addressList.querySelectorAll('.user-addresslist');
                for (var i = 0; i < items.length; i++) {
                    items[i].classList.remove('defaultAddr');
                }
                // 将点击的li元素添加defaultAddr类名
                evt.target.classList.add('defaultAddr');
                console.log("evt:"+evt.target)
                //获取点击li标签里的省市区收货人电话的值
                address(evt.target)

            }
        });

        var address=function (_this) {
            const province = _this.querySelector(".province").textContent.trim();
            const city = _this.querySelector(".city").textContent.trim();
            const district = _this.querySelector(".dist").textContent.trim();
            const address = _this.querySelector(".street").textContent.trim();
            const name = _this.querySelector(".buy-user").textContent.trim();
            const phone = _this.querySelector(".buy-phone").textContent.trim();
            const addId = _this.querySelector(".addId").textContent.trim();

            const addIdEl=document.getElementById("addId");
            const provinceEL=document.getElementById("sheng");
            const cityEL=provinceEL.nextElementSibling;
            const districtEL=cityEL.nextElementSibling;
            const addressEL=districtEL.nextElementSibling;
            provinceEL.textContent =province;
            cityEL.textContent =city;
            districtEL.textContent =district;
            addressEL.textContent =address;

            const nameEL=document.getElementById("shouhuoren");
            const phoneEL=nameEL.nextElementSibling;
            nameEL.textContent =name;
            phoneEL.textContent=phone;
            //提交订单的地址ID
            addIdEl.value=addId;
        }
        // 等待页面加载完毕
        window.onload = function() {
            // 找到 class 为 user-addresslist defaultAddr 的 li 元素
            var defaultLi = document.querySelector('li.user-addresslist.defaultAddr');
            console.log("defaultLi:"+defaultLi)
            // 对获取到的元素进行操作，例如添加样式等
            address(defaultLi);
            //提交订单的cartId  ids


        }
    });
</script>

<script type="text/javascript">
    //配置插件目录
    layui.config({
        base: '/mods/'
        , version: '1.0'
    });
    layui.use([ "layer", "form","element","layarea"], function () {

        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var layarea = layui.layarea;


        layarea.render({
            elem: '#area-picker',
            change: function (res) {
                console.log(res);
            }
        });

        $("body").on("click", "#saveBtn", function () {
            form.render()
            var data = form.val("addressForm");
            if(data.contactName==null||data.contactName === ""){
                layer.msg("收货人不能为空")
                return false;
            }if(data.phone==null||data.phone === ""){
                layer.msg("手机号不能为空")
                return false;
            }if(data.province==null||data.province === ""){
                layer.msg("省份不能为空")
                return false;
            }if(data.city==null||data.city === ""){
                layer.msg("市不能为空")
                return false;
            }if(data.district==null||data.district === ""){
                layer.msg("区不能为空")
                return false;
            }if(data.address==null||data.address === ""){
                layer.msg("详细地址不能为空")
                return false;
            }
            // var data = $('#addressForm').serialize();
            console.log(data);
            layer.confirm("点击确认新增成功",function () {
                $.post("/information/addMemberAddress", data, function () {
                    window.location.reload();
                });
            });
        })

    })

</script>
</body>
</html>